from django.shortcuts import render,render_to_response
from django.template import loader,Context
from django.http import HttpResponse
from news.models import Xinwen_st,Xinwen_gf
from django.core.paginator import Paginator,InvalidPage,EmptyPage,PageNotAnInteger


def  show_list1(request):
 	Xinwenst = Xinwen_st.objects.order_by('-id')
	after_range_num = 5
 	befor_range_num = 4 
	try:
		page = int(request.GET.get("page",1))
		if page < 1:
			page = 1
	except ValueError:
		page = 1
	paginator = Paginator(Xinwenst,7)
	try:
		Xinwenst_list = paginator.page(page)
	except(EmptyPage,InvalidPage,PageNotAnInteger):
		Xinwenst_list = paginator.page(paginator.num_pages)
	if page >= after_range_num:
		page_range = paginator.page_range[page-after_range_num:page+befor_range_num]
	else:
		page_range = paginator.page_range[0:int(page)+befor_range_num]
	return render_to_response('news.html',{'Xinwenst_list':Xinwenst_list,'page_range':page_range})
'''
def  shou_list2(request):
 	Xinwengf = Xinwen_gf.objects.order_by('-id')
	after_range_num = 5
 	befor_range_num = 4
	try:
		page = int(request.GET.get("page",1))
	if page < 1:
		page = 1
	except ValueError:
		page = 1
		paginator = Paginator(Xinwengf,7)
	try:
		Xinwengf_list = paginator.page(page)
	except(EmptyPage,InvalidPage,PageNotAnInteger):
		Xinwengf_list = paginator.page(paginator.num_pages)
	if page >= after_range_num:
		page_range = paginator.page_range[page-after_range_num:page+befor_range_num]
	else:
		page_range = paginator.page_range[0:int(page)+befor_range_num]
	return render-to_response('news.html',{'Xinwengf_list':Xinwengf_list,'page_range':page_range})

'''